export default defineContentScript({
  matches: ['https://www.gigab2b.com/*'],
  world: 'MAIN',
  async main() {
    const originSend = window.XMLHttpRequest.prototype.send;
    window.XMLHttpRequest.prototype.send = function (...args) {
      const data = args[0];
      try {
        const dataObj = JSON.parse(data as string);
        if (dataObj.page && dataObj.limit) {
          // console.log(dataObj);
          // 传递到另一个 content-script 中
          window.postMessage({ type: 'GIGAB2B_COLLECT_DATA', data: dataObj }, '*');
        }
      } catch (error) {
        console.log(error);
      }
      return originSend.apply(this, args);
    };
  },
});
